﻿package mortal.game.scene3D.player.entity
{
    import Message.BroadCast.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import baseEngine.modifiers.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.event.*;
    import mortal.game.events.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.display3d.blood.*;
    import mortal.game.scene3D.events.*;
    import mortal.game.scene3D.map3D.AstarAnyDirection.data.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.utils.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class PetPlayer extends MovePlayer
    {
        private var _effectPlayerArray:Vector.<EffectPlayer>;
        private var _footPlayer:EffectPlayer;

        public function PetPlayer()
        {
            this._effectPlayerArray = new Vector.<EffectPlayer>;
            return;
        }// end function

        override public function hoverTest(param1:Number, param2:Number, param3:Number, param4:Number) : Boolean
        {
            return false;
        }// end function

        override protected function walkGridStart(param1:AstarTurnPoint) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap && entityInfo.isSelf)
            {
                this.sendServerNextPoint();
            }
            else
            {
                super.walkGridStart(param1);
            }
            return;
        }// end function

        override public function diversion(param1:Array) : void
        {
            var _loc_2:AstarTurnPoint = null;
            if (param1.length)
            {
                _loc_2 = param1[(param1.length - 1)];
                setRealPoint(_loc_2._x, _loc_2._y);
            }
            super.diversion(param1);
            return;
        }// end function

        override public function walking(param1:Array) : void
        {
            var _loc_2:AstarTurnPoint = null;
            if (param1.length)
            {
                _loc_2 = param1[(param1.length - 1)];
                setRealPoint(_loc_2._x, _loc_2._y);
            }
            if (GameMapUtil.curMapState.isPetBreakMap && entityInfo.isSelf)
            {
                if (isInitInfo == false || this.isDead)
                {
                    return;
                }
                if (param1.length == 0)
                {
                    return;
                }
                _pathArray = param1.concat();
                startMove();
                nextPathPoint(true);
                this.sendServerNextPoint();
            }
            else
            {
                super.walking(param1);
            }
            return;
        }// end function

        override protected function walkGridEnd() : void
        {
            super.walkGridEnd();
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                FrEventDispatcher.instance.proxyDispatchEvent(this, PlayerEvent.GIRD_WALK_END, [this]);
            }
            return;
        }// end function

        protected function sendServerNextPoint() : void
        {
            var _loc_1:SPoint = null;
            if (_nextPoint)
            {
                _loc_1 = new SPoint();
                _loc_1.x = _nextPoint._x;
                _loc_1.y = _nextPoint._y;
                Dispatcher.dispatchEvent(new DataEvent(EventName.SelfPetCopyMove, _loc_1));
            }
            return;
        }// end function

        override protected function updateOther(param1:SEntityInfo, param2:Boolean = true) : void
        {
            if (param2)
            {
                this.updateModel();
            }
            super.updateOther(param1, param2);
            return;
        }// end function

        override protected function updateVIP() : void
        {
            this.updateModel();
            return;
        }// end function

        override public function updateModel() : void
        {
            var _loc_1:EntityModelInfo = null;
            var _loc_2:int = 0;
            var _loc_3:String = null;
            var _loc_4:Vector.<Array> = null;
            var _loc_5:Array = null;
            var _loc_6:Array = null;
            var _loc_7:EffectPlayer = null;
            super.updateModel();
            if (_bodyPlayer)
            {
                _loc_1 = PetUtil.getPetModel(1, entityInfo.petModelId);
                if (!_loc_1.mesh)
                {
                    return;
                }
                _bodyPlayer.load(_loc_1.mesh + ".md5mesh", _loc_1.bone + ".skeleton", _loc_1.texture);
                _bodyPlayer.scaleValue = PetUtil.petScaleValue(_loc_1.proportion1);
                hoverLeft = _loc_1.hoverLeft;
                hoverTop = _loc_1.hoverTop;
                hoverWidth = _loc_1.hoverWidth;
                hoverHeight = _loc_1.hoverHeight;
                _loc_2 = 0;
                while (_loc_2 < this._effectPlayerArray.length)
                {
                    
                    _loc_7 = this._effectPlayerArray[_loc_2];
                    _bodyPlayer.unHang(_loc_7);
                    _loc_7.dispose();
                    _loc_2++;
                }
                this._effectPlayerArray = new Vector.<EffectPlayer>;
                if (_loc_1.effect && (entityInfo.isPetItem || VipConfig.instance.isShowEffect(EVipRecordType._EVipRecordTypePetEffect, entityInfo.entityInfo.VIP)))
                {
                    _loc_4 = GameStrUtil.alzToArray(_loc_1.effect);
                    _loc_5 = _loc_4[0];
                    _loc_6 = _loc_4[1];
                    _loc_2 = 0;
                    while (_loc_2 < _loc_5.length)
                    {
                        
                        _loc_7 = EffectPlayerPool.instance.getEffectPlayer(_loc_5[_loc_2], _bodyPlayer, null, true);
                        this._effectPlayerArray[_loc_2] = _loc_7;
                        if (_loc_6.length > _loc_2)
                        {
                            _loc_7.hangBoneName = _loc_6[_loc_2];
                            _bodyPlayer.hang(_loc_7);
                        }
                        if (_loc_7.temple is TempleRole)
                        {
                            (_loc_7.temple as TempleRole).setRoleParams(_bodyPlayer, null, null);
                        }
                        _loc_7.play(PlayMode.ANIMATION_LOOP_MODE);
                        _loc_2++;
                    }
                }
                if (this._footPlayer)
                {
                    this._footPlayer.dispose();
                    this._footPlayer = null;
                }
                _loc_3 = GameDefConfig.instance.getPetGrowthFootEffect(1);
                if (_loc_3)
                {
                    this._footPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_3, _bodyPlayer, null, true);
                    this._footPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                }
                this.updateName();
                this.updateNamePosition();
            }
            return;
        }// end function

        override public function updateName(param1:String = null, param2:Boolean = true) : void
        {
            var _loc_3:* = NameUtil.getPetName(_entityInfo, _entityInfo.entityInfo.name);
            entityInfo.updateIsEnemy();
            super.updateName(_loc_3, param2);
            return;
        }// end function

        override protected function getBloodType() : int
        {
            if (EntityRelationUtil.isFriend(entityInfo.entityInfo))
            {
                return EBloodType.Role;
            }
            return EBloodType.OtherPlayer;
        }// end function

        override public function updateHeadContainer() : void
        {
            var _loc_1:* = entityInfo.isInLayer;
            var _loc_2:* = this.selected;
            var _loc_3:* = SystemSetting.instance.isHideLife.bValue;
            var _loc_4:* = SystemSetting.instance.isHideOterPlayerName.bValue;
            var _loc_5:* = SystemSetting.instance.isHideTitle.bValue;
            var _loc_6:* = SystemSetting.instance.isHideGuildName.bValue;
            _headContainner.updateNameVisible(_loc_1 && !GameMapUtil.isInHideNameMap && (!_loc_4 || _loc_2 || this.entityInfo.isAttackRole));
            _headContainner.updateGuildVisible(_loc_1 && (!_loc_6 && !(_loc_4 && !_loc_2)));
            _headContainner.updateTitleVisible(_loc_1 && !GameMapUtil.isInHideTitleMap && !_loc_5);
            return;
        }// end function

        override public function updateLife(param1:int, param2:int, param3:Boolean = false) : void
        {
            return;
        }// end function

        override public function updateLevel(param1:int, param2:Boolean) : void
        {
            return;
        }// end function

        override public function updateGrowthMax(param1:int) : void
        {
            var _loc_2:EntityModelInfo = null;
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:Vector.<Array> = null;
            var _loc_6:Array = null;
            var _loc_7:Array = null;
            var _loc_8:EffectPlayer = null;
            if (_bodyPlayer)
            {
                _loc_2 = PetUtil.getPetModel(1, _entityInfo.entityInfo.model);
                _bodyPlayer.load(_loc_2.mesh + ".md5mesh", _loc_2.bone + ".skeleton", _loc_2.texture);
                hoverLeft = _loc_2.hoverLeft;
                hoverTop = _loc_2.hoverTop;
                hoverWidth = _loc_2.hoverWidth;
                hoverHeight = _loc_2.hoverHeight;
                if (_loc_2.effect)
                {
                    _loc_5 = GameStrUtil.alzToArray(_loc_2.effect);
                    _loc_6 = _loc_5[0];
                    _loc_7 = _loc_5[1];
                    _loc_4 = 0;
                    while (_loc_4 < _loc_6.length)
                    {
                        
                        if (this._effectPlayerArray.length > _loc_4)
                        {
                            _loc_8 = this._effectPlayerArray[_loc_4];
                            _bodyPlayer.unHang(_loc_8);
                            _loc_8.dispose();
                        }
                        _loc_8 = EffectPlayerPool.instance.getEffectPlayer(_loc_6[_loc_4], _bodyPlayer, null, true);
                        this._effectPlayerArray[_loc_4] = _loc_8;
                        _loc_8.hangBoneName = _loc_7[_loc_4];
                        _bodyPlayer.hang(_loc_8);
                        _loc_8.play(PlayMode.ANIMATION_LOOP_MODE);
                        _loc_4++;
                    }
                }
                if (this._footPlayer)
                {
                    this._footPlayer.dispose();
                    this._footPlayer = null;
                }
                _loc_3 = GameDefConfig.instance.getPetGrowthFootEffect(param1);
                if (_loc_3)
                {
                    this._footPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_3, _bodyPlayer, null, true);
                    this._footPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                }
            }
            return;
        }// end function

        override public function get type() : int
        {
            return EEntityType._EEntityTypePet;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            while (_loc_2 < this._effectPlayerArray.length)
            {
                
                _bodyPlayer.unHang(this._effectPlayerArray[_loc_2]);
                this._effectPlayerArray[_loc_2].dispose();
                _loc_2++;
            }
            this._effectPlayerArray.length = 0;
            if (this._footPlayer)
            {
                this._footPlayer.dispose();
                this._footPlayer = null;
            }
            super.dispose(param1);
            return;
        }// end function

    }
}
